package cn.com.bluemoon.daps.common.toolkit.valueobject;

import cn.com.bluemoon.daps.common.exception.DapThrowException;
import cn.com.bluemoon.daps.common.toolkit.AesEncryptUtils;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * @author Jarod.Kong
 * @date 2021-06-06 14:44
 **/
@Data
public class PtSsh {
    private String host, username, password;
    private String port;

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("host", host)
                .append("username", username)
                .append("port", port)
                .append("password", StrUtil.repeat("*", password.length()))
                .toString();
    }

    public Integer getPortD(){
        try {
            return Integer.valueOf(AesEncryptUtils.decrypt(this.port+""));
        } catch (Exception e) {
            throw new DapThrowException("解密服务器端口号失败", e);
        }
    }

    public String getHostD(){
        try {
            return AesEncryptUtils.decrypt(this.host);
        } catch (Exception e) {
            throw new DapThrowException("解密服务器ip失败", e);
        }
    }

    public String getUsernameD(){
        try {
            return AesEncryptUtils.decrypt(this.username);
        } catch (Exception e) {
            throw new DapThrowException("解密服务器用户失败", e);
        }
    }

    public String getPasswordD(){
        try {
            return AesEncryptUtils.decrypt(password);
        } catch (Exception e) {
            throw new DapThrowException("解密服务器密码失败", e);
        }
    }
}
